/* $RCSFile: ADNDynActivityParty.cs $
 * Apache license v2 2011 by Christian Surieux
 * $Source: ?/CRMWrapper3/DynEntities/ADNDynActivityParty.cs $
 * $log$
 * Revision 6 2010/08/06 19:56:32  christian.surieux
 *   Added Log to All cs files
 */

using System;
using System.Diagnostics;
using System.Collections;
using System.ComponentModel;
using System.Collections.Generic;
using System.Text;
using CrmSdk;

namespace AddonNice.CRMWrapper
{
	public class ADNDynActivityParty : DynEntity
	{
        protected class Ftor: DFactor
        {
            public Ftor() : base(CrmStr.activityparty)
            {}

            public override Type DynType
            { get { return typeof(ADNDynActivityParty); } }

            public override string DynTypename
            {   get{ return CrmStr.activityparty;}}

            public override DynEntity Build()
            {
                return new ADNDynActivityParty();
            }
            public override DynEntity Build(CRMWrapperBase w, InternalDynamicEntity dEntity, PropertyDescriptorCollection wproperties)
            {   
                return new ADNDynActivityParty(w, dEntity, wproperties, null);
            }

            public override DynEntity Build(CRMWrapperBase w,string PrimFieldVal)
            {   return new ADNDynActivityParty(w);}

            public override DynEntity Build(CRMWrapperBase w,Guid PrimaryKeyValue)
            {   return new ADNDynActivityParty(w,PrimaryKeyValue);}
        }

        static ADNDynActivityParty(){new Ftor();} 

        public override bool HasPrimaryField
        {
            get{   return false;}
        }

        public override bool HasBusinessUnitProperty
        {
            get{   return false;}
        }

        public override bool HasOwningBusinessUnitProperty
        {
            get{   return false;}
        }

        public override bool HasOwnerProperty
        {
            get{   return false;}
        }

        /// <summary>
		/// Reserved for template methods: do not use directly
		/// </summary>
        public ADNDynActivityParty(): base()
		{}

        public ADNDynActivityParty(CRMWrapperBase w)
			: base(w, CrmStr.activityparty)
		{}

		public ADNDynActivityParty(CRMWrapperBase w, Guid CrmId)
			: base(w,CrmStr.activityparty, CrmId)
		{}

        public ADNDynActivityParty(ResetWrapperHandler fn)
			: base(fn, CrmStr.activityparty)
		{}

		public ADNDynActivityParty(ResetWrapperHandler fn, Guid CrmId)
			: base(fn,CrmStr.activityparty, CrmId)
		{}
    
		public ADNDynActivityParty(CRMWrapperBase w, InternalDynamicEntity e)
			: base(w,CrmStr.activityparty,e,null,null)
		{}

		public ADNDynActivityParty(CRMWrapperBase w, InternalDynamicEntity e,PropertyDescriptorCollection prop,InternalColumnSet s)
           : base(w,CrmStr.activityparty,e,prop,s)
		{}

		public ADNDynActivityParty(ResetWrapperHandler fn, InternalDynamicEntity e)
			: base(fn,CrmStr.activityparty,e,null,null)
		{}

		public ADNDynActivityParty(ResetWrapperHandler fn, InternalDynamicEntity e,PropertyDescriptorCollection prop,InternalColumnSet s)
           : base(fn,CrmStr.activityparty,e,prop,s)
		{}

        [CrmDynAttribute(CrmStr.activityparty)]
		public Guid activitypartyid
		{
			get
			{
				return KeyPropertyValue(CrmStr.activitypartyid);
			}
			set
			{
				AddKeyProperty(CrmStr.activitypartyid, value);
			}
		}

        protected override void SetCrmIdProperty(Guid crmId)
        {
           if ( !dicProperty.ContainsKey(CrmStr.activitypartyid) || KeyPropertyValue(CrmStr.activitypartyid) != crmId )
                activitypartyid  =   crmId;
        }

        public override Guid PrimaryKeyGuidValue
        {
           get
           {
                return activitypartyid;
           }
           set
           {
               activitypartyid    =   value;
           }
        }

        string _DefaultPartyName   =   CrmStr.account;
		public string DefaultPartyName
		{
			get
			{
				return _DefaultPartyName;
			}
			set
			{
                switch (value)
                {
                    case CrmStr.account:
                    case CrmStr.contact:
                    case CrmStr.systemuser:
                    case CrmStr.lead:
                        _DefaultPartyName  =   value;
                        break;
                }
			}
		}
       
        /// <summary>
        /// Gets the ID of the activity associated with the activity party. A "party" is any person who is associated with an activity.
        /// </summary>
        [CrmDynAttribute(CrmStr.activityparty)]
		public Guid partyid
		{
            get
            {
                return LookupPropertyValue(CrmStr.partyid);
            }
            set
            {
                AddLookupProperty(CrmStr.partyid,DefaultPartyName,value);
            }
        }

        /// <summary>
        /// Gets the schema name of the party 
        /// </summary>
		public string partyType
		{
            get
            {
                return LookupPropertyType(CrmStr.partyid);
            }
        }

        /// <summary>
        /// Gets the primaryfield value ( name for account) of the party 
        /// </summary>
		public string partyName
		{
            get
            {
                return LookupPropertyName(CrmStr.partyid);
            }
        }

        /// <summary>
        /// Gets the ID of the activity associated with the activity party. A "party" is any person who is associated with an activity.
        /// </summary>
        [CrmDynAttribute(CrmStr.activityparty)]
		public Guid activityid
		{
            get
            {
                return LookupPropertyValue(CrmStr.activityid);
            }
            set
            {
                AddLookupProperty(CrmStr.activityid,CrmStr.activitypointer,value);
            }
        }

 
        /// <summary>
        /// Gets or sets the name of the property from the related party to use as the e-mail address to which an e-mail is delivered. 
        /// </summary>
        [CrmDynAttribute(CrmStr.activityparty)]
        public string addressused
        {
            get
            {
                return StringPropertyValue(CrmStr.addressused);
            }
            set
            {
                AddStringProperty(CrmStr.addressused,value);
            }
        }

        /// <summary>
        /// Gets or sets the ID of the resource specification for the activity party. 
        /// </summary>
        [CrmDynAttribute(CrmStr.activityparty)]
		public Guid resourcespecid
		{
            get
            {
                return LookupPropertyValue(CrmStr.resourcespecid);
            }
            set
            {
                AddLookupProperty(CrmStr.resourcespecid,CrmStr.resourcespec,value);
            }
        }


        /// <summary>
        /// Gets or sets the scheduled end time of the e-mail activity. 
        /// </summary>
        [CrmDynAttribute(CrmStr.activityparty)]
        public string scheduledend
        {
            get
            {
                return DateTimePropertyValue(CrmStr.scheduledend);
            }
            set
            {
                AddDateTimeProperty(CrmStr.scheduledend,value);
            }
        }

        /// <summary>
        /// Gets or sets the scheduled start time of the e-mail activity. 
        /// </summary>
        [CrmDynAttribute(CrmStr.activityparty)]
        public string scheduledstart
        {
            get
            {
                return DateTimePropertyValue(CrmStr.scheduledstart);
            }
            set
            {
                AddDateTimeProperty(CrmStr.scheduledstart,value);
            }
        }

        /// <summary>
        /// Gets a value that indicates whether to allow sending e-mail to the activity party. 
        /// </summary>
        [CrmDynAttribute(CrmStr.activityparty)]
        public bool donotemail
        {
            get
            {
                return BooleanPropertyValue(CrmStr.donotemail);
            }
            set
            {
                AddBooleanProperty(CrmStr.donotemail,value);
            }
        }

        /// <summary>
        /// Gets the value that indicates whether to allow sending faxes to the activity party. 
        /// </summary>
        [CrmDynAttribute(CrmStr.activityparty)]
        public bool donotfax
        {
            get
            {
                return BooleanPropertyValue(CrmStr.donotfax);
            }
            set
            {
                AddBooleanProperty(CrmStr.donotfax,value);
            }
        }
 
        /// <summary>
        /// Gets the value that indicates whether to allow phone calls to the activity party. 
        /// </summary>
        [CrmDynAttribute(CrmStr.activityparty)]
        public bool donotphone
        {
            get
            {
                return BooleanPropertyValue(CrmStr.donotphone);
            }
            set
            {
                AddBooleanProperty(CrmStr.donotphone,value);
            }
        }
 
        /// <summary>
        /// Gets the value that indicates whether to allow sending postal mail to the activity party. 
        /// </summary>
        [CrmDynAttribute(CrmStr.activityparty)]
        public bool donotpostalmail
        {
            get
            {
                return BooleanPropertyValue(CrmStr.donotpostalmail);
            }
            set
            {
                AddBooleanProperty(CrmStr.donotpostalmail,value);
            }
        }
    
        /// <summary>
        /// Gets or sets the amount of effort used by the resource in a service appointment activity. 
        /// </summary>
        [CrmDynAttribute(CrmStr.activityparty)]
        public double effort
        {
            get
            {
                return DoublePropertyValue(CrmStr.effort);
            }
            set
            {
                AddFloatProperty(CrmStr.effort,value);
            }
        }
 
        /// <summary>
        /// Gets or sets the role of the person in the activity, such as sender, to, cc, bcc, required, optional, organizer, regarding, or owner. 
        /// </summary>
        [CrmDynAttribute(CrmStr.activityparty)]
        public int participationtypemask
        {
            get
            {
                return PicklistPropertyIntValue(CrmStr.participationtypemask);
            }
            set
            {
                AddPicklistProperty(CrmStr.participationtypemask,value);
            }
        }

        public  DynEntity ExtractParty(bool isAdmin)
        {
            if ( !ContainsKey(CrmStr.partyid) )
                return null;
            DynEntity dyn       =   DynEntity.Create2RetrieveDynamicEntity(wrapper,partyType,partyid);
            if ( isAdmin)
                 dyn.adminRetrieve();
            else dyn.Retrieve();
            return dyn;
        }

        public InternalActivityParty CreateActivityParty()
        {
            return wrapper.CreateActivityParty(this);
        }

        protected override Guid internalCreate(bool isAdmin)
        { 
            const string msg    =   "[E]ADNDynActivityParty Create unvailable on this entity";
            if ( CRMDynTraceSwitch.Sw.TraceError)
                Trace.WriteLine( msg,CRMDynTraceSwitch.Sw.Info);
            throw new Exception(msg);
        }

        protected override void internalUpdate(bool isAdmin)
        {
            const string msg    =   "[E]ADNDynActivityParty Update unvailable on this entity";
            if ( CRMDynTraceSwitch.Sw.TraceError)
                Trace.WriteLine( msg,CRMDynTraceSwitch.Sw.Info);
            throw new Exception(msg);
        }
        protected override void internalDelete(bool isAdmin)
        {
            const string msg    =   "[E]ADNDynActivityParty Delete unvailable on this entity";
            if ( CRMDynTraceSwitch.Sw.TraceError)
                Trace.WriteLine( msg,CRMDynTraceSwitch.Sw.Info);
            throw new Exception(msg);
        }

        protected override bool internalRetrieve(bool isAdmin)
        {
            const string msg    =   "[E]ADNDynActivityParty Retrieve unvailable on this entity";
            if ( CRMDynTraceSwitch.Sw.TraceError)
                Trace.WriteLine( msg,CRMDynTraceSwitch.Sw.Info);
            throw new Exception(msg);
        }

        protected override void internalAssign(Guid userId, bool isAdmin)
        {
            const string msg    =   "[E]ADNDynActivityParty Assign unvailable on this entity";
            if ( CRMDynTraceSwitch.Sw.TraceError)
                Trace.WriteLine( msg,CRMDynTraceSwitch.Sw.Info);
            throw new Exception(msg);
        }
    }
}
